package com.situ.day2;

import java.util.Arrays;

import org.junit.Test;

public class ArrayDemo {
	@Test
	public void test1() {
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 45;
		array[2] = 3;
		array[3] = 17;
		System.out.println(array.length);
		System.out.println(array[0]);
		System.out.println(array[1]);
		System.out.println(array[array.length - 1]);
		System.out.println("------------");
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		System.out.println("------------");
		//倒着输出
		for (int i = array.length - 1; i >= 0; i--) {
			System.out.println(array[i]);
		}
		//计算数组里面值的累加和
		int sum = 0;
		for (int i = 0; i < array.length; i++) {
			sum += array[i];
		}
		System.out.println("sum:" + sum);
		
	}
	
	public static void main(String[] args) {
		int[] scores = { 0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9 };
		int[] counts = new int[10];
		for (int i = 0; i < scores.length; i++) {
			switch (scores[i]) {
			case 0:
				counts[0]++;
				break;
			case 1:
				counts[1]++;
				break;
			case 2:
				counts[2]++;
				break;
			case 3:
				counts[3]++;
				break;
			case 4:
				counts[4]++;
				break;
			case 5:
				counts[5]++;
				break;
			case 6:
				counts[6]++;
				break;
			case 7:
				counts[7]++;
				break;
			case 8:
				counts[8]++;
				break;
			case 9:
				counts[9]++;
				break;
			default:
				break;
			}
		}
		System.out.println("0~9出现的次数依次为：");
		for (int j = 0; j < counts.length; j++) {
			System.out.print(counts[j] + " ");
		}
	}
	
	@Test
	public void test7() {
		int[] counts = new int[10];
		int[] scores = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		for (int i = 0 ; i < scores.length ; i++) {
			counts[scores[i]] += 1;
		}
		for (int i = 0; i < counts.length; i++) {
			System.out.println("数字" + i + "出现的次数为" + counts[i]);
		}
	}
	
	@Test
	public void test33() {
		int[] scores = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int count = 0;
		for (int i = 0; i <= 9; i++) {
			for (int j = 0; j < scores.length; j++) {
				if (i == scores[j]) {
					count++;
				}
			}
			System.out.println(i + "出现次数：" + count );
			count = 0;
		}
	}

	@Test
	public void test444() {
		int[] array = {40, 17, 21,  1};
		for (int i = 1; i <= array.length - 1; i++) {
			for (int j = 0; j < array.length - i; j++) {
				if (array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
		}
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
	}
	
	
	
	
	
	
	
	
	
	

}
